#include<bits/stdc++.h>
using namespace std;
int T,n,m,L,V,d[100009],v[100009],a[100009],w[100009],ans1;
double p[100009];
bitset<100009>u;
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>T;
    while(T--)
    {
        u.reset();
        ans1=0;
        cin>>n>>m>>L>>V;
        for(int i=1;i<=n;++i)
            cin>>d[i]>>v[i]>>a[i];
        for(int i=1;i<=m;++i)
            cin>>p[i];
        for(int i=1;i<=n;++i)
        {
            int nxt=lower_bound(p+1,p+m+1,d[i])-p;
            if(nxt>n)
            {
                w[i]=-1;
                continue;
            }
            if(a[i]==0||(v[i]<=V&&a[i]<0)||(v[i]>V&&a[i]>0))
            {
                if(v[i]<=V)
                    w[i]=-1;
                else
                {
                    w[i]=-2;
                    ++ans1;
                }
                continue;
            }
            double s=(V*V-v[i]*v[i])/(2.0*a[i]);
            if(d[i]+s>p[m])
            {
                w[i]=-1;
                continue;
            }
            int pos;
            if(a[i]>0)pos=upper_bound(p+nxt,p+m+1,d[i]+s)-(p+nxt);
            else pos=lower_bound(p+nxt,p+m+1,d[i]+s)-(p+nxt)-1;
            if(pos<1||pos>n)
                w[i]=-1;
            else
            {
                w[i]=pos;
                ++ans1;
            }
        }
        cout<<ans1<<' ';
        int flag=0;
        for(int i=1;i<=n;++i)
        {
            if(w[i]>0)
            {
                flag=1;
                break;
            }
            if(w[i]==-2)
                flag=-2;
        }
        if(flag==1)
        {
            const int tmpm=m;
            bool _2=false;
            for(int i=1;i<=n;++i)
            {
                if(w[i]==-2)
                {
                    _2=true;
                    break;
                }
            }
            for(int i=1;i<=n;++i)
                if(w[i]>0&&!u[w[i]])
                {
                    --m;
                    u[w[i]]=1;
                }
            if(_2&&u[tmpm]==0)--m;
            cout<<m<<'\n';
        }
        else if(flag==0)cout<<m<<'\n';
        else cout<<m-1<<'\n';
    }
    return 0;
}